<template>
    <el-form :model="regulationForm" :rules="regulationRules" ref="regulationForm" label-width="180px" size="mini">
        <el-form-item label="执行事件类型" prop="eventType">
            <el-select v-model="regulationForm.eventType" filterable>
                <el-option v-for="item in eventTypeOptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="执行对象" prop="pushObject">
            <el-select v-model="regulationForm.pushObject" filterable>
                <el-option v-for="item in pushObjectOptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="提醒对象">
            <select-tree ref="tree" :instructType="instructType" :editInfo="editInfo" :isGetAllLabel="false"></select-tree>
        </el-form-item>
        <div class="messagePushWrapper__3LKkF">
            <div class="title__NIfjx">推送内容</div>
            <el-form-item label="标题" prop="title">
                <el-input v-model="regulationForm.title" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="工单编号" prop="workOrderCode">
                <el-input v-model="regulationForm.workOrderCode" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="产品名称" prop="productName">
                <el-input v-model="regulationForm.productName" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="时间" prop="time">
                <el-input v-model="regulationForm.time" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="推送内容" prop="comment">
                <el-input type="textarea" v-model="regulationForm.comment" placeholder="请输入" :autosize="{ minRows: 5}">
                </el-input>
            </el-form-item>
        </div>
    </el-form>
</template>

<script>
    import selectTree from '@/components/selectTree'
    export default {
        data() {
            return {
                regulationForm: {
                    eventType: 0,
                    pushObject: 0,
                    userId:'',
                    depId:'',
                    title:'',
                    workOrderCode:'',
                    productName:'',
                    time:'',
                    comment: ''
                },
                eventTypeOptions: [{
                    value: 0,
                    label: '消息推送'
                }],
                pushObjectOptions: [{
                    value: 0,
                    label: '微信-消息通知'
                }],
                regulationRules: {
                    title: [{
                        required: true,
                        message: '标题不能为空!',
                        trigger: 'change'
                    }],
                    workOrderCode: [{
                        required: true,
                        message: '工单编号不能为空!',
                        trigger: 'change'
                    }],
                    productName: [{
                        required: true,
                        message: '产品名称不能为空!',
                        trigger: 'change'
                    }],
                    time: [{
                        required: true,
                        message: '时间不能为空!',
                        trigger: 'change'
                    }],
                    comment: [{
                        required: true,
                        message: '推送内容不能为空!',
                        trigger: 'change'
                    }],
                    eventType: [{
                        required: true,
                    }],
                    pushObject: [{
                        required: true,
                    }],
                },
                editInfo:{
                    userId:'',
                    depId:'',
                    selectNames:''
                }
            }
        },
        props:{
            instructType:{
                type: String,
                default: 'create'
            }
        },
        components:{
            selectTree
        },
        methods: {
            //搜集表单项数据
            getExecuteRuleInfo(){
                const {userId,depId} = this.$refs.tree.getTreeInfo()
                let data = {
                    eventType: this.regulationForm.eventType,
                    pushObject: this.regulationForm.pushObject,
                    userId,
                    depId,
                    pushMessVo:{
                        title:this.regulationForm.title,
                        workOrderCode:this.regulationForm.workOrderCode,
                        productName:this.regulationForm.productName,
                        time:this.regulationForm.time,
                        comment: this.regulationForm.comment
                    }
                }
                return data
            },
            receiveProp(row){
                const {eventType,pushObject,pushMessVo,depId,userId,depNames,userNames} = row
                this.regulationForm.eventType = eventType
                this.regulationForm.pushObject = pushObject
                this.regulationForm.title = pushMessVo.title
                this.regulationForm.workOrderCode = pushMessVo.workOrderCode
                this.regulationForm.productName = pushMessVo.productName
                this.regulationForm.time = pushMessVo.time
                this.regulationForm.comment = pushMessVo.comment
                this.editInfo.userId = userId
                this.editInfo.depId = depId
                this.editInfo.selectNames = this.utils.handleNames(userNames,depNames)
            },
            inspectForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.$emit('handleConfirm')
                    } else {
                        return false;
                    }
                });
            },
            open(){
                this.$nextTick(()=>{
                    this.$refs.tree.handleDefaultValue(this.instructType)
                })
            },
            resetForm() {
                this.$refs.tree.clearTreeInfo()
                this.$refs.regulationForm.resetFields()
            }
        }
    }
</script>

<style lang="less" scoped>
    .messagePushWrapper__3LKkF {
        background-color: #e5e5e5;
        padding: 15px 0 15px;

        .title__NIfjx {
            font-size: 12px;
            padding-left: 15px;
        }
    }

    /deep/ .el-select {
        width: 80%;
    }

    .el-input,
    .el-textarea {
        width: 80%;
    }
</style>